/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.platform.api.entity;

import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.medusa.gruul.common.data.base.BaseNoTenantEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.math.BigDecimal;

/**
 * <p>
 * 代理商统计信息表结构
 * </p>
 *
 * @author whh
 * @since 2020-10-04
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("t_agent_statistics")
@ApiModel(value = "AgentStatistics对象", description = "代理商统计信息表结构")
public class AgentStatistics extends BaseNoTenantEntity {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * t_agent_info 表中id
     */
    @ApiModelProperty(value = "t_agent_info 表中id")
    @TableField("agent_info_id")
    private Long agentInfoId;

    /**
     * 累计销售总金额
     */
    @ApiModelProperty(value = "累计销售总金额")
    @TableField("total_sale_price")
    private BigDecimal totalSalePrice;

    /**
     * 累计销售总单数
     */
    @ApiModelProperty(value = "累计销售总单数")
    @TableField("total_sale_count")
    private Integer totalSaleCount;

    /**
     * 佣金金额
     */
    @ApiModelProperty(value = "佣金金额")
    @TableField("commission_amount")
    private BigDecimal commissionAmount;

    /**
     * 下集渠道商数
     */
    @ApiModelProperty(value = "下级渠道商数")
    @TableField("channal_count")
    private Integer channalCount;

    /**
     * 商户数量
     */
    @ApiModelProperty(value = "商户数量")
    @TableField("shop_info_count")
    private Integer shopInfoCount;

    /**
     * 店铺数量
     */
    @ApiModelProperty(value = "店铺数量")
    @TableField("app_info_count")
    private Integer appInfoCount;


    public void sumTotalSalePrice(BigDecimal newValue) {
        this.totalSalePrice = NumberUtil.round(this.totalSalePrice.add(newValue), 2);
    }

    public void sumCommissionAmount(BigDecimal newValue) {
        this.commissionAmount = NumberUtil.round(this.commissionAmount.add(newValue), 2);
    }

    public void sumTotalSaleCount(Integer newValue) {
        this.totalSaleCount = NumberUtil.add(this.totalSaleCount, newValue).intValue();

    }

    public void sumChannalCount(Integer newValue) {
        this.channalCount = NumberUtil.add(this.channalCount, newValue).intValue();

    }

    public void sumShopInfoCount(Integer newValue) {
        this.shopInfoCount = NumberUtil.add(this.shopInfoCount, newValue).intValue();

    }

    public void sumAppInfoCount(Integer newValue) {
        this.appInfoCount = NumberUtil.add(this.appInfoCount, newValue).intValue();
    }

    public void subTotalSalePrice(BigDecimal newValue) {
        this.totalSalePrice = NumberUtil.round(this.totalSalePrice.subtract(newValue), 2);
    }

    public void subCommissionAmount(BigDecimal newValue) {
        this.commissionAmount = NumberUtil.round(this.commissionAmount.subtract(newValue), 2);
    }

    public void subTotalSaleCount(Integer newValue) {
        this.totalSaleCount = Math.max(NumberUtil.sub(this.totalSaleCount, newValue).intValue(),0);

    }

    public void subChannalCount(Integer newValue) {
        this.channalCount = Math.max(NumberUtil.sub(this.channalCount, newValue).intValue(), 0);

    }

    public void subShopInfoCount(Integer newValue) {
        this.shopInfoCount = Math.max(NumberUtil.sub(this.shopInfoCount, newValue).intValue(),0);

    }

    public void subAppInfoCount(Integer newValue) {
        this.appInfoCount = Math.max(NumberUtil.sub(this.appInfoCount, newValue).intValue(),0);
    }
}
